{
  "properties" : { },
  "id" : "8a0b72733e104196a61d3fb0d35552c0",
  "script" : null,
  "groupId" : "b56a24453f064cf8bf33b13a4a2a6d91",
  "name" : "查询运行负载前50名数据",
  "createTime" : 1727071151150,
  "updateTime" : 1726043986609,
  "lock" : "1",
  "createBy" : "ndmp",
  "updateBy" : "ndmp",
  "path" : "deviceTopFifty",
  "method" : "GET",
  "parameters" : [ {
    "name" : "type",
    "value" : "1",
    "description" : "",
    "required" : false,
    "dataType" : "Integer",
    "type" : "",
    "defaultValue" : "",
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ ]
  } ],
  "options" : [ ],
  "requestBody" : "",
  "headers" : [ ],
  "paths" : [ ],
  "responseBody" : "{\n    \"status\": 200,\n    \"message\": \"success\",\n    \"data\": [\n        {\n            \"id\": \"D3185894866505691434\",\n            \"deviceName\": \"SN-YL.TaiChangGF.R\",\n            \"cpuUsage\": \"75\",\n            \"memUsage\": \"48\",\n            \"delayTime\": \"14.725\",\n            \"packetLoss\": \"0\"\n        },\n        {\n            \"id\": \"D2964600861434994050\",\n            \"deviceName\": \"SN1.R1\",\n            \"cpuUsage\": \"21.91\",\n            \"memUsage\": \"35.73\",\n            \"delayTime\": \"0.7115\",\n            \"packetLoss\": \"0\"\n        },\n        {\n            \"id\": \"D2324439623524418802\",\n            \"deviceName\": \"SN-YLHJ-NE40.R1\",\n            \"cpuUsage\": \"15.67\",\n            \"memUsage\": \"20.17\",\n            \"delayTime\": \"10.1325\",\n            \"packetLoss\": \"0\"\n        },\n        {\n            \"id\": \"D9136120488132190197\",\n            \"deviceName\": \"SN-DJBHJ.R1\",\n            \"cpuUsage\": \"15.5\",\n            \"memUsage\": \"20.67\",\n            \"delayTime\": \"0.464\",\n            \"packetLoss\": \"0\"\n        },\n        {\n            \"id\": \"D6580367373910439760\",\n            \"deviceName\": \"ShanXi_NE40-X8\",\n            \"cpuUsage\": \"15.45\",\n            \"memUsage\": \"25.27\",\n            \"delayTime\": \"0.16475\",\n            \"packetLoss\": \"0\"\n        },\n        {\n            \"id\": \"D1726804845555087060\",\n            \"deviceName\": \"SN-XYBHJ.R1\",\n            \"cpuUsage\": \"15.33\",\n            \"memUsage\": \"21\",\n            \"delayTime\": \"4.8775\",\n            \"packetLoss\": \"0\"\n        },\n        {\n            \"id\": \"D6608104449626114426\",\n            \"deviceName\": \"SN-LCBHJ.R1\",\n            \"cpuUsage\": \"15.33\",\n            \"memUsage\": \"17.83\",\n            \"delayTime\": \"4.9775\",\n            \"packetLoss\": \"0\"\n        },\n        {\n            \"id\": \"D7415114813343755042\",\n            \"deviceName\": \"SN.YHBHJ.R1\",\n            \"cpuUsage\": \"15.22\",\n            \"memUsage\": \"19.33\",\n            \"delayTime\": \"8.78\",\n            \"packetLoss\": \"0\"\n        },\n        {\n            \"id\": \"D7943911817013833820\",\n            \"deviceName\": \"SXYA-ZhongShanFD-1R\",\n            \"cpuUsage\": \"15\",\n            \"memUsage\": \"29.5\",\n            \"delayTime\": \"11.575\",\n            \"packetLoss\": \"0\"\n        },\n        {\n            \"id\": \"D1643816517374081464\",\n            \"deviceName\": \"SN2.XX.R1\",\n            \"cpuUsage\": \"14.27\",\n            \"memUsage\": \"18.09\",\n            \"delayTime\": \"2.3225\",\n            \"packetLoss\": \"0\"\n        },\n        {\n            \"id\": \"D3602382218928185367\",\n            \"deviceName\": \"SN-DYBHJ.R1\",\n            \"cpuUsage\": \"14\",\n            \"memUsage\": \"21\",\n            \"delayTime\": \"3.375\",\n            \"packetLoss\": \"0\"\n        },\n        {\n            \"id\": \"D6748872627444240188\",\n            \"deviceName\": \"SN_SL.WeiDongGF.R\",\n            \"cpuUsage\": \"12.5\",\n            \"memUsage\": \"13.5\",\n            \"delayTime\": \"10.549999\",\n            \"packetLoss\": \"0\"\n        },\n        {\n            \"id\": \"D1910764354242122839\",\n            \"deviceName\": \"525G_28U_Test\",\n            \"cpuUsage\": \"12\",\n            \"memUsage\": \"52\",\n            \"delayTime\": \"0.259\",\n            \"packetLoss\": \"0\"\n        },\n        {\n            \"id\": \"D8983500847812012009\",\n            \"deviceName\": \"ShanXi-BD-SR8812\",\n            \"cpuUsage\": \"11.5\",\n            \"memUsage\": \"28.5\",\n            \"delayTime\": \"4.76\",\n            \"packetLoss\": \"0\"\n        },\n        {\n            \"id\": \"D8620796006457025282\",\n            \"deviceName\": \"SXYA-MingShaShanFD-1R\",\n            \"cpuUsage\": \"11.5\",\n            \"memUsage\": \"29\",\n            \"delayTime\": \"11.325\",\n            \"packetLoss\": \"0\"\n        },\n        {\n            \"id\": \"D2007640281165320194\",\n            \"deviceName\": \"SN-YL.MingShuiHuFD.R\",\n            \"cpuUsage\": \"11\",\n            \"memUsage\": \"28.5\",\n            \"delayTime\": \"11.950001\",\n            \"packetLoss\": \"0\"\n        },\n        {\n            \"id\": \"D8355823176948079902\",\n            \"deviceName\": \"SN-HZ.GuangYiB.R\",\n            \"cpuUsage\": \"10\",\n            \"memUsage\": \"10\",\n            \"delayTime\": \"8.57\",\n            \"packetLoss\": \"0\"\n        },\n        {\n            \"id\": \"D1482757912635666600\",\n            \"deviceName\": \"SN-YL.KongJiaYanFD.R\",\n            \"cpuUsage\": \"10\",\n            \"memUsage\": \"10\",\n            \"delayTime\": \"11.375001\",\n            \"packetLoss\": \"0\"\n        },\n        {\n            \"id\": \"D7175563092666679777\",\n            \"deviceName\": \"SN2-XY.R1\",\n            \"cpuUsage\": \"9\",\n            \"memUsage\": \"15.6\",\n            \"delayTime\": \"6.6575\",\n            \"packetLoss\": \"0\"\n        },\n        {\n            \"id\": \"D2296382032955233120\",\n            \"deviceName\": \"SN-YL.LeiJiaShanFD.R\",\n            \"cpuUsage\": \"9\",\n            \"memUsage\": \"17.5\",\n            \"delayTime\": \"11.325\",\n            \"packetLoss\": \"0\"\n        },\n        {\n            \"id\": \"D1862224474573476513\",\n            \"deviceName\": \"SN2-SL.R1\",\n            \"cpuUsage\": \"8.8\",\n            \"memUsage\": \"16.2\",\n            \"delayTime\": \"5.0675\",\n            \"packetLoss\": \"0\"\n        },\n        {\n            \"id\": \"D4081373158299718321\",\n            \"deviceName\": \"SN-HZBHJ.R1\",\n            \"cpuUsage\": \"8.8\",\n            \"memUsage\": \"16\",\n            \"delayTime\": \"4.9625\",\n            \"packetLoss\": \"0\"\n        },\n        {\n            \"id\": \"D4213284220006664719\",\n            \"deviceName\": \"SN2-HZ.R1\",\n            \"cpuUsage\": \"8.8\",\n            \"memUsage\": \"15.6\",\n            \"delayTime\": \"8.49\",\n            \"packetLoss\": \"0\"\n        },\n        {\n            \"id\": \"D5712702224277450498\",\n            \"deviceName\": \"SN2-TC.R1\",\n            \"cpuUsage\": \"8.8\",\n            \"memUsage\": \"15.6\",\n            \"delayTime\": \"6.2625003\",\n            \"packetLoss\": \"0\"\n        },\n        {\n            \"id\": \"D1000770367644387389\",\n            \"deviceName\": \"SN-XA.750_JingWeiB.R\",\n            \"cpuUsage\": \"8.67\",\n            \"memUsage\": \"4.67\",\n            \"delayTime\": \"8.32\",\n            \"packetLoss\": \"0\"\n        },\n        {\n            \"id\": \"D1814237884760947677\",\n            \"deviceName\": \"SN2.BD.R1\",\n            \"cpuUsage\": \"8.6\",\n            \"memUsage\": \"16.2\",\n            \"delayTime\": \"9.29\",\n            \"packetLoss\": \"0\"\n        },\n        {\n            \"id\": \"D1919858423792924342\",\n            \"deviceName\": \"SN2.AK.R1\",\n            \"cpuUsage\": \"8.4\",\n            \"memUsage\": \"15.8\",\n            \"delayTime\": \"8.3\",\n            \"packetLoss\": \"0\"\n        },\n        {\n            \"id\": \"D8396117811237249314\",\n            \"deviceName\": \"SN2-BJ.R1\",\n            \"cpuUsage\": \"8.2\",\n            \"memUsage\": \"15.8\",\n            \"delayTime\": \"4.0425\",\n            \"packetLoss\": \"0\"\n        },\n        {\n            \"id\": \"D1262673079037166813\",\n            \"deviceName\": \"SN-YuLinDingBianB.R\",\n            \"cpuUsage\": \"7.83\",\n            \"memUsage\": \"8.67\",\n            \"delayTime\": \"16.025\",\n            \"packetLoss\": \"0\"\n        },\n        {\n            \"id\": \"D5160521551247044692\",\n            \"deviceName\": \"ShanXi-SR8812\",\n            \"cpuUsage\": \"7.75\",\n            \"memUsage\": \"28.5\",\n            \"delayTime\": \"0.55125\",\n            \"packetLoss\": \"0\"\n        }\n    ]\n}",
  "description" : "",
  "requestBodyDefinition" : {
    "name" : "",
    "value" : { },
    "description" : "",
    "required" : false,
    "dataType" : "String",
    "type" : "",
    "defaultValue" : "",
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ ]
  },
  "responseBodyDefinition" : {
    "name" : "",
    "value" : { },
    "description" : "",
    "required" : false,
    "dataType" : "String",
    "type" : "",
    "defaultValue" : "",
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ ]
  }
}
================================
import redis
import cn.hutool.core.collection.CollectionUtil
import org.apache.commons.collections.MapUtils
import java.util.stream.Collectors
import java.util.Comparator
import java.util.Collections
import java.lang.Double

var token = header.get("blade-auth")::string;
var dccId = redis.get(token.substring(7))

var sql = """
SELECT
	id,device_name
FROM
	ndmp_device 
WHERE
	mtnc_status = 0   and dcc_id=#{dccId}
	
"""

var res = new ArrayList();
var res = db.select(sql)
var TYPE_CPU = 1;
var TYPE_MEN = 2;
var TYPE_DELAY_TIME = 3;
var TYPE_PACKET_LOSS = 4;
var fileds = Arrays.asList("cpuUsage", "memUsage", "delayTime", "packetLoss")


for (vo in res) {
    var pointSoftVersion = redis.getPoint(vo.id, fileds);

    if (CollectionUtil.isNotEmpty(pointSoftVersion)) {
        var cpuUsage = pointSoftVersion[0].cpuUsage
        var memUsage = pointSoftVersion[0].memUsage
        var delayTime = pointSoftVersion[0].delayTime
        var packetLoss = pointSoftVersion[0].packetLoss
        vo.cpuUsage = cpuUsage;
        vo.memUsage = memUsage;
        vo.delayTime = delayTime;
        vo.packetLoss = packetLoss;
    }

}


String alias
if (type == TYPE_CPU) {
    alias = "cpuUsage"
} else if (type == TYPE_MEN) {
    alias = "memUsage"
} else if (type == TYPE_DELAY_TIME) {
    alias = "delayTime"
} else {
    alias = "packetLoss"
}

// 排序过程
Collections.sort(res, Comparator.comparingDouble(m -> Double.valueOf(m.get(alias) == null ? "0" : m.get(alias))).reversed());


return res.stream().limit(30)